package cn.com.infohold.smartcity.bean;

import android.content.Context;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 用于List Dialog的传入, 传出结果
 * Created by liangdengke on 2015/8/15.
 */
public class DialogEntity implements Serializable {

    /** 上下文Context */
    Context mContext;
    /** 请求码 */
    private int requestCode;
    /** 结果码, 1 代表选择了, 0 代表用户退出 */
    private int resultCode;
    /** 在Dialog需要显示的List<String> */
    private List<String> list;
    /** Dialog是否允许Cancel, 默认允许 */
    private boolean isCancel = true;
    /** 是否显示选择格,默认不显示 */
    private boolean choiceImage = false;
    /** 是否多选, 默认单选 true -- 多选, false --- 单选 */
    private boolean isMultiChoice = false;
    /** 是否有确认按钮  默认没有*/
    private boolean hasAccept = false;
    /** 选中的位置 */
    private List<Integer> result = new ArrayList<>();
    /** 传出的结果(String) */
    private List<String> resultStrList;
    /** 传入的结果,单选 */
    private String resultStr;
    /** 标题, 可以不设, 默认不显示 */
    private String title;

    private boolean isSearchKey=false;

    private boolean isNotNull=false;


    /**
     * 构造函数
     * @param context    上下文
     * @param list        传入的List<String>
     */
    public DialogEntity(Context context, List<String> list){
        this.list = list;
        this.mContext = context;
    }
    /**
     * 构造函数
     * @param context    上下文
     */
    public DialogEntity(Context context){
        this.mContext = context;
    }
    /**
     * 获取点击的String列表,
     * @return
     */
    public List<String> getResultStrList(){
        checkState();
        if(resultStrList == null){
            resultStrList = new ArrayList<>();
            for(Integer integer : result){
                resultStrList.add(list.get(integer));
            }
        }
        return resultStrList;
    }

    /**
     * 获取第一个选择项, 也是单选情况下的唯一
     * @return  第一个选择项
     */
    public int getFirstPosition(){
        checkState();
        return result.get(0);
    }

    private void checkState() {
        if(resultCode == 0){
            throw new IllegalStateException("用户选择了退出,状态不正确");
        }
    }


    /**
     * 返回 mContext的值
     *
     * @return value of mContext
     */
    public Context getContext() {
        return mContext;
    }

    /**
     * 返回 requestCode的值
     *
     * @return value of requestCode
     */
    public int getRequestCode() {
        return requestCode;
    }

    /**
     * 设置requestCode
     *
     * @param requestCode 要设置的requestCode
     */
    public void setRequestCode(int requestCode) {
        this.requestCode = requestCode;
    }

    /**
     * 返回 resultCode的值
     *
     * @return value of resultCode
     */
    public int getResultCode() {
        return resultCode;
    }

    /**
     * 设置resultCode
     *
     * @param resultCode 要设置的resultCode
     */
    public void setResultCode(int resultCode) {
        this.resultCode = resultCode;
    }


    /**
     * 返回 result的值
     *
     * @return value of result
     */
    public List<Integer> getResult() {
        checkState();
        return result;
    }

    /**
     * 设置result
     *
     * @param result 要设置的result
     */
    public void setResult(List<Integer> result) {
        this.result = result;
    }
    /**
     * 返回 list的值
     *
     * @return value of list
     */
    public List<String> getList() {
        return list;
    }

    /**
     * 设置list
     *
     * @param list 要设置的list
     */
    public void setList(List<String> list) {
        this.list = list;
    }

    /**
     * 返回 isCancel的值
     *
     * @return value of isCancel
     */
    public boolean isCancel() {
        return isCancel;
    }

    /**
     * 设置isCancel
     *
     * @param isCancel 要设置的isCancel
     */
    public void setIsCancel(boolean isCancel) {
        this.isCancel = isCancel;
    }

    /**
     * 返回 choiceImage的值
     *
     * @return value of choiceImage
     */
    public boolean isChoiceImage() {
        return choiceImage;
    }

    /**
     * 设置choiceImage
     *
     * @param choiceImage 要设置的choiceImage
     */
    public void setChoiceImage(boolean choiceImage) {
        this.choiceImage = choiceImage;
    }

    /**
     * 返回 isMultiChoice的值
     *
     * @return value of isMultiChoice
     */
    public boolean isMultiChoice() {
        return isMultiChoice;
    }

    /**
     * 设置isMultiChoice
     *
     * @param isMultiChoice 要设置的isMultiChoice
     */
    public void setIsMultiChoice(boolean isMultiChoice) {
        this.isMultiChoice = isMultiChoice;
    }

    /**
     * 返回 hasAccept的值
     *
     * @return value of hasAccept
     */
    public boolean isHasAccept() {
        return hasAccept;
    }

    /**
     * 设置hasAccept
     *
     * @param hasAccept 要设置的hasAccept
     */
    public void setHasAccept(boolean hasAccept) {
        this.hasAccept = hasAccept;
    }

    /**
     * 返回 title的值
     *
     * @return value of title
     */
    public String getTitle() {
        return title;
    }

    /**
     * 设置title
     *
     * @param title 要设置的title
     */
    public void setTitle(String title) {
        this.title = title;
    }

    public String getResultStr() {
        return resultStr;
    }

    public void setResultStr(String resultStr) {
        this.resultStr = resultStr;
    }

    public boolean isSearchKey() {
        return isSearchKey;
    }

    public void setIsSearchKey(boolean isSearchKey) {
        this.isSearchKey = isSearchKey;
    }

    public boolean isNotNull() {
        return isNotNull;
    }

    public void setIsNotNull(boolean isNotNull) {
        this.isNotNull = isNotNull;
    }
}
